package org.s170.servlet.WebServlet;

import org.s170.dao.NoteDao;
import org.s170.entity.Note;
import org.s170.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/api/addNote.do")
public class AddNoteServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String title = req.getParameter("title");
        String[] notetype =req.getParameter("notetype").split(",");
        String tid = notetype[0];
        String typename = notetype[1];
        int uistop = Integer.parseInt(req.getParameter("uistop"));
        String typed = req.getParameter("isyc");
        String images=req.getParameter("pic");
        String content = req.getParameter("contentHtml");
        String zscontent=req.getParameter("contentText");
        String uname= req.getParameter("username");

        if (uname==null || "".equals(uname)){
            print(resp,errorJson("请先登录"));
            return;
        }

        NoteDao noteDao = new NoteDao();
        Note note =new Note(tid,typename,title,uname,content,zscontent,typed,uistop,images);

        int row=noteDao.addNote(note);
        print(resp,successJson(row));
    }
}
